package com.xinzhilibrary.controller;

import com.xinzhilibrary.model.InnerOrderInfo;
import com.xinzhilibrary.model.Result;
import com.xinzhilibrary.service.InnerOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@CrossOrigin
public class OrderInfoController {

    @Autowired
    private InnerOrderService innerOrderService;

    /**
     * 新增进货订单+管理员支付
     * @param innerOrderInfo 内部订单信息，从请求体中读取
     * @param token 认证令牌，从请求头中读取
     * @return 操作结果，包含成功或错误信息
     */
    @PostMapping("/insertInnerGoodsOrder")
    public Result insertIGO(@RequestBody InnerOrderInfo innerOrderInfo, @RequestHeader("Authorization") String token) {
        return innerOrderService.insertInnerOrder(innerOrderInfo, token);
    }

    /**
     *  清空用户订单
     * @param orderGoodsUserId  //用户ID
     * @param token //认证令牌，从请求头中读取
     * @return //操作结果，包含成功或错误信息
     */
    @PostMapping( "/clearUserOrder " )
    public Result clearUserOrder(int orderGoodsUserId, @RequestHeader("Authorization") String token) {
        return innerOrderService.clearOrder(orderGoodsUserId, token);
    }

    /**
     * 管理员支付订单
     * @param igoStatus 订单状态
     * @param token  //认证令牌，从请求头中读取
     * @return Result
     */
    @PostMapping("/payForOrder")
    public Result payForOrder(int igoStatus, @RequestHeader("Authorization") String token) {
        return innerOrderService.payForOrder(igoStatus, token);
    }
}

